package com.itheima.d10_api_object;

import java.util.Objects;

/*
    Object类 :
        toString方法
        equals方法
 */
public class Test1 {
    public static void main(String[] args) {
        people p1=new people("貂蝉",15);
        people p2=new people("貂蝉",15);
//        p1=null;
//        p1.equals(p2);
//        System.out.println(p1.equals(p2));
//        p2=p1;
//        System.out.println(p1==p2);
//        System.out.println(p1.toString());
//        System.out.println(p2.toString());

        System.out.println(Objects.equals(p1, p2));//调用了Object的equals方法。

//        p1=null;
//        System.out.println(Objects.isNull(p1));
//        System.out.println(Objects.nonNull(p1));

    }
}
class people{
    private String name;
    private int age;

    public people() {
    }

    public people(String name, int age) {
        this.name = name;
        this.age = age;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        people people = (people) o;
        return age == people.age && Objects.equals(name, people.name);
    }

    @Override
    public String toString() {
        return "people{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }
    //    @Override
//    public int hashCode() {
//        return Objects.hash(name, age);
//    }
}












